package com.freewater.javabase.demo.network.auth;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.MalformedURLException;
import java.net.URL;

public class SecureSourceViewer {
    public static void main(String[] args) throws MalformedURLException {
        Authenticator.setDefault(new DialogAuthenticator());
        URL url = new URL("http://127.0.0.1:8080/manager/status"); // tomcat 管理控制台，使用basic的http授权验证
        try (BufferedInputStream is = new BufferedInputStream(url.openStream()); InputStreamReader reader = new InputStreamReader(is)) {
            char[] buff = new char[1024];
            int read;
            while ((read = reader.read(buff)) != -1) {
                String str = new String(buff, 0, read);
                System.out.print(str);
            }
            System.out.println();
        } catch (IOException e) {
            System.out.println(e);
        } catch (Exception e) {
            System.out.println(e);
        }
        System.exit(0);
    }
}
